package ru.housewife.reports;

import ru.housewife.form.IngredientForm;

import java.util.*;

/**
 * TODO: add description
 *
 * @author atroshanin
 */
public class IngredientReportObject implements Comparable<IngredientReportObject> {

    private IngredientForm ingredient;

    private Map<Long, WareReportObject> wareROs = new HashMap<Long, WareReportObject>();

    private List<WareReportObject> wareROsSorted;

    public IngredientReportObject(IngredientForm ingredient) {
        this.ingredient = ingredient;
    }

    public IngredientForm getIngredient() {
        return ingredient;
    }

    public List<WareReportObject> getWareROs() {
        return wareROsSorted;
    }

    public WareReportObject getWareRO(long wareId) {
        return wareROs.get(wareId);
    }

    public void addWareReportObject(WareReportObject wareRO) {
        wareROs.put(wareRO.getWareView().getWare().getId(), wareRO);
    }

    public void sortWares() {
        wareROsSorted = new ArrayList<WareReportObject>(wareROs.values());
        Collections.sort(wareROsSorted);
    }

    @Override
    public int compareTo(IngredientReportObject that) {
        return this.ingredient.compareTo(that.ingredient);
    }
}
